﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Birthday
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

      
        //弹出
        private void button2_Click(object sender, EventArgs e)
        {

        }
        //浏览
        private void button4_Click(object sender, EventArgs e)
        {
            //点击后到浏览好友信息
            new Thread(() => {
                Application.Run(new Form3());
            }).Start();
            this.Close();
        }
        /// <summary>
        /// 新增好友信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            var Num1 = textBox1.Text;
            var Num2 = textBox5.Text;
            var Num3 = textBox6.Text;
            var Num4 = comboBox1.Text;
            var Num5 = textBox4.Text;
            var Num6 = textBox3.Text;
            var Num7 = textBox2.Text;
            var con = "server=.;database=Information;integrated security=true";
            using (var conn = new SqlConnection(con))
            {
                conn.Open();

                if (Num1 == "" || Num2 == "" || Num3 == "" || Num4 == "" || Num5 == "" || Num6 == "" || Num7 == "")
                {
                    MessageBox.Show("好友信息不能为空");
                    conn.Close();
                }

                if (conn.State == ConnectionState.Open)
                {
                    var cmd = new SqlCommand($"insert  Remind (Name,Birthday,Age,Sex,QQ,Phone,Wechat) values('{Num1}','{Num2}','{Num3}','{Num4}','{Num5}','{Num6}','{Num7}')", conn);
                    var ret = cmd.ExecuteNonQuery();
                    if (ret > 0)
                    {
                        MessageBox.Show("好友信息添加成功");
                    }
                }
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            //让最小化窗口不在任务栏
            this.ShowInTaskbar = false;
        }

        private void 恢复页面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Normal;
        }

        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定要关闭程序吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("确定要关闭程序吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
    }
}
